﻿using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows;

using SynergyControls;
using SynergyLib.DSP;
using SharpDX.XAudio2;

namespace XAudio2Controls
{
    public class RingModulationPanel : EffectsPanel, IEffectParams
    {
        public float ModFreq
        {
            get { return DialAngle1 / 360 * 440; }            
        }

        public float RingFreq
        {
            get { return DialAngle2 / 360 * 880; }
        }

        public RingModulationEffect rm { get; set; }

        static RingModulationPanel()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(RingModulationPanel), new FrameworkPropertyMetadata(typeof(EffectsPanel)));
        }

         public RingModulationPanel(SubmixVoice submixer, Collection<EffectDescriptor> fxChainReference)
        {
            FxChain = fxChainReference;
            EffectParams = this;
            effectType = EffectTypes.RingModulation;
            Submixer = submixer;
            this.Effect = new RingModulationEffect();           
            rm = (RingModulationEffect)Effect;
            this.effectDescriptor = new EffectDescriptor(Effect);
        }

        protected override void UpdateParameters()
        {
            if (ParameterEnabled)
            {

                RingModulationParams prms = new RingModulationParams()
                {
                    ModFreq = this.Param1,
                    RingFreq = this.Param2,
                };
                rm.Parameters = prms;
                
            }
        }
        protected override void UpdateIntensity()
        {
            //rm.Intensity = (float)IntensitySliderValue;
        }

        #region IEffectParams
        public float Param1
        {
            get
            {
                ParamLabel1Content = GetParam1Readout();
                return ModFreq;
            }
        }
        public float Param2
        {
            get
            {
                ParamLabel2Content = GetParam2Readout();
                return RingFreq;
            }
        }
        public float Param3
        {
            get;
            set;
        }
        public float Param4
        {
            get;
            set;
        }

        public string ParamName1
        {
            get
            {
                return "ModFreq";
            }
        }
        public string ParamName2
        {
            get
            {
                return "RingFreq";
            }
        }
        public string ParamName3
        {
            get
            {
                return GetParam3Readout();
            }
        }
        public string ParamName4
        {
            get
            {
                return GetParam4Readout();
            }
        }

        public string GetParam1Readout()
        {
            return Math.Round(ModFreq, 2).ToString() + "Hz";
        }
        public string GetParam2Readout()
        {
            return Math.Round(RingFreq, 2).ToString() + "Hz";
        }
        public string GetParam3Readout()
        {
            return null;
        }
        public string GetParam4Readout()
        {
            return null;
        }
        #endregion IEffectParams
    }
}
